import { api } from './baseRequest';

// 微信素材相关API
export const wechatMaterialApi = {
  // 获取素材总数
  getMaterialCount: async () => {
    try {
      return await api.get('/wechat/material/count');
    } catch (error) {
      console.error('获取素材总数失败:', error);
      throw error;
    }
  },

  // 获取文件素材列表
  getMaterialFileBatch: async (type, keyword, offset = 0, count = 20) => {
    try {
      return await api.get('/wechat/material/file/list', {
        params: { type, keyword, offset, count }
      });
    } catch (error) {
      console.error('获取文件素材列表失败:', error);
      throw error;
    }
  },

  // 获取图文素材列表
  getMaterialNewsBatch: async (offset = 0, count = 20) => {
    try {
      return await api.get('/wechat/material/news/list', {
        params: { offset, count }
      });
    } catch (error) {
      console.error('获取图文素材列表失败:', error);
      throw error;
    }
  },

  // 删除素材
  deleteMaterial: async (mediaId) => {
    try {
      return await api.delete(`/wechat/material?mediaId=${mediaId}`);
    } catch (error) {
      console.error('删除素材失败:', error);
      throw error;
    }
  }
};

export default wechatMaterialApi;